package fr.louloutes.lolshooter.engine.objects.weapons;

import android.graphics.Rect;
import fr.louloutes.lolshooter.engine.objects.GameObject;
import fr.louloutes.lolshooter.engine.sprites.LolSprite;

/**
 * Class Projectile: handling of any kind of bullet
 * 
 * @author Louloute
 * 
 */
public class Projectile extends GameObject
{

	Weapon weapon;

	/**
	 * Constructor with initializations
	 * 
	 * @param sprite
	 * @param weapon
	 */
	public Projectile( LolSprite sprite, Weapon weapon )
	{
		super( sprite );
		this.weapon = weapon;
	}

	/* (non-Javadoc)
	 * @see fr.louloutes.lolshooter.engine.GameObject#move(long, android.graphics.Rect)
	 * 
	 * Update projectile position
	 */
	public void move( long ellapsedTime, Rect frameRect )
	{
		double module = weapon.speed * ellapsedTime;
		double xDelta = module * Math.cos( weapon.angle );
		double yDelta = module * Math.sin( weapon.angle );

		double newX = getX() + xDelta;
		double newY = getY() + yDelta;
		setPosition( newX, newY );
	}

	/**
	 * Return the corresponding weapon.
	 */
	public Weapon getWeapon()
	{
		return weapon;
	}

}
